set more off   
  quietly log   
  local logon = r(status)   
  if "`logon'" == "on" {  
	log close  
	}  

***********************************************
* File name: densely-ge-replication.do        *
* Date: August 16, 2023                       *
* Author: Carly Millerd                       *
* Purpose: Model Do file for "Dispute
* Resolution through Densely Gender-Equal IOs *
* Input file: rev50_io_gender_mid.dta         *                revindividual_mid_io.       
* Stata Version: Analyses Using Stata 18      *
* ******************************************* *

***********DEMAND SIDE MODELS AND MARGINS GRAPHS***************
//using rev.dta - this is the demand side model
use revindividual_mid_io.dta, clear
//Model 1 using mid initiator and gender lag, full sample, and country mixed effects. 
xtset ccode1
xtlogit mid_initiate gendense_lag inclusive_lag numio_lag defense_lag libdem_lag cinc_lag cumulative_in_lag gdp_lag time time2 time3
estimates store initiate_full

//Model 2 using mid initiator and gender lag, subset by better -than-median gender-exclusivity scores, and country mixed effects
xtset ccode1
xtlogit mid_initiate gendense_lag inclusive_lag numio_lag defense_lag libdem_lag cinc_lag cumulative_in_lag gdp_lag time time2 time3 if inclusive_lag>.636
estimates store initiate_inclusive

*Figure 1
margins, at(gendense_lag=(0(25)120)) atmeans
marginsplot, scheme(s1color) ///
	recast(connected) plotopts(mcolor(black) msymbol(S) lcolor(gs4)) ///
	recastci(rarea) ciopts(fcolor(gs12*0.25%50) lcolor(gs8)) ///
	xtitle("Number of Densely Gender Equal IOs") ///
	ytitle("Probability of Initiating a MID") ///
	title("") ///
	ylabel(#5, labsize(medsmall) angle(0) grid) ///
		note("Predicted probability from logistic model of initiating a MID." ///
	  "Shaded area represents a 95% confidence interval.") ///
	  title("Figure 1: Predicted Probability of Initiating a MID" ///
	  "Decreases with Increased Membership in Densely Gender Equal IOs", size(medsmall))


//Table 1: Individual State coefficient reports
esttab initiate_full initiate_inclusive ///
using millerd-shared-ios-table1.rtf, replace b(%9.3f) ///
	se transform(ln*: exp(2*@) exp(2*@)) stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) ///
	star(* .05 ** .01 *** .001) ///
	mlabel("Model 1" "Model 2") ///
	eqlabels("" "Var(Group Level Errors)", none) ///
	varlabels(gendense_lag "Number of Densely Gender Equal IOs" numio_lag "Number of IOs" defense_lag "Defensive Alliance" libdem_lag "Democracy Score" inclusive_lag "Gender Inclusivity Score" cinc_lag "CINC Score" cumulative_in_lag "Cumulative MIDs" gdp_lag "GDP (logged)" time "Time" time2 "Time Squared" time3 "Time Cubed"  _cons "Constant" /lnsig2u "Sigma") ///
	title("Table 1: Full Model Testing the Impact of Membership in Densely Gender-Equal IOs on State Initiation of MIDs")


********SUPPLY SIDE MODELS AND MARGINS GRAPHS**************	
	
	
//using "Threshold 50 dataset" for H2 - these are the supply side models
use revthreshold50_io_gender_mid, clear

//Model 3 - lagged with mid as DV with only defense alliances and politically relevant dyads
xtset dyad_id
xtlogit mid gendense_lag numio_lag libdem1 libdem2 inclusive1 inclusive2 defense_lag cont_lag kmdist_lag trade_lag cinc_lag cumulative_lag time time2 time3 if poli_relevant==1
estimates store dyad_mid

//margins plot for Model 3
margins, at(gendense_lag=(0(10)60)) atmeans
marginsplot, scheme(s1color) ///
	recast(connected) plotopts(mcolor(black) msymbol(S) lcolor(gs4)) ///
	recastci(rarea) ciopts(fcolor(gs12*0.25%50) lcolor(gs8)) ///
		ytitle("Probability of MID Onset") ///
		xtitle("Number of Shared Densely Gender Equal IOs", size(vsmall)) ///
	title("Predicted Probability of All Dyads", size(vsmall)) ///
	ylabel(#5, labsize(medsmall) angle(0) grid) ///
	   name(margins_dyad_mid, replace)

//Model 4: Using Mitchell's (2002) Approach where a dyad with at least 1 gender unequal state is coded as 1 (gender unequal dyad)	
xtset dyad_id
xtlogit mid gendense_lag numio_lag libdem1 libdem2 inclusive1 inclusive2 defense_lag cont_lag kmdist_lag trade_lag cinc_lag cumulative_lag time time2 time3 if poli_relevant==1 & genderweak==1
estimates store unequal_mid

// Margins plot for Model 4
margins, at(gendense_lag=(0(10)60)) atmeans
marginsplot, scheme(s1color) ///
	recast(connected) plotopts(mcolor(black) msymbol(S) lcolor(gs4)) ///
	recastci(rarea) ciopts(fcolor(gs12*0.25%50) lcolor(gs8)) ///
	xtitle("Number of Shared Densely Gender Equal IOs", size(vsmall)) ///
	ytitle("") ///
	ylabel(#5, labsize(medsmall) angle(0) grid) ///
		  title("Predicted Probability for Gender Unequal Dyads", size(vsmall)) ///
	  	  name(margins_unequal_mid,replace)		  
		  
//Figure 2: Combining the margins plots for Models 3 and 4
graph combine margins_dyad_mid margins_unequal_mid, scheme(s1mono) ///
rows(1) imargin(medium) ///
	iscale(*1.25) ///
	title("Figure 2: Joint Membership in Densely Gender Equal IOs" ///
	"Decreases Likelihood of MID Participation", size(small)) ///
	note("Predicted probability from logistic model of onset of a MID between politically relevant states." ///
	  "Shaded area represents a 95% confidence interval.") 
	 
//Table 2:
esttab dyad_mid unequal_mid ///
using millerd-shared-ios-table1.rtf, replace b(%9.3f) ///
	se transform(ln*: exp(2*@) exp(2*@)) stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) ///
	star(* .05 ** .01 *** .001) ///
	mlabel("Model 3" "Model 4") ///
	eqlabels("" "Var(Group Level Errors)", none) ///
	varlabels(gendense_lag "Number of Shared Densely Gender Equal IOs" numio_lag "Number of IOs" defense_lag "Defensive Alliance" libdem1 "Democracy Score, Country 1" libdem2 "Democracy Score, Country 2" inclusive1 "Inclusivity Score, Country 1" inclusive2 "Inclusivity Score, Country 2" cinc_lag "CINC Score" cont_lag "Contiguity" kmdist_lag "Capital Distance"trade_lag "Trade Dependency" cumulative_lag "Cumulative MIDs" gdp_lag "GDP (logged)" time "Time" time2 "Time Squared" time3 "Time Cubed"  _cons "Constant" /lnsig2u "Sigma") ///
	title("Table 2: Impact of Shared Membership in Densely Gender-Equal IOs on Dyad Participation in MIDs")

//Figure 3:
use revindividual_mid_io.dta

scatter genderinclusive1 libdem1 if year==2002 & genderinclusive1>=.865, scheme(s1mono) jitter(100) mlabel(CountryCode) ytitle("Gender Inclusivity") title("Figure 3: Relationship between Liberal Democracy and Gender Inclusivity", size(medsmall)) note("Data is from 2002, midway through the data time period." ///
 "Countries are in the top 75th percentile for gender equality in this year.", size(small)) 

	  
//APPENDIX MODELS
use revindividual_mid_io.dta, clear
//Appendix 1: correlation table for individual state models
corr  mid_initiate gendense_lag numio_lag libdem_lag inclusive_lag defense_lag gdp_lag cinc_lag cumulative_in_lag time time2 time3


//Appendix A2: using mid initiate and an interaction term between democracy and gender-dense IOs, in gender-equal states
xtset ccode1
xtlogit mid_initiate c.gendense_lag##c.libdem_lag numio_lag defense_lag inclusive_lag cinc_lag cumulative_in_lag gdp_lag time time2 time3 if inclusive_lag>.636
estimates store appendix_m2

*table A2:
esttab appendix_m2 ///
using millerd-shared-ios-table1.rtf, replace b(%9.3f) ///
	se transform(ln*: exp(2*@) exp(2*@)) stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) ///
	star(* .05 ** .01 *** .001) ///
	mlabel("Interaction Model") ///
	eqlabels("" "Var(Group Level Errors)", none) ///
	varlabels(gendense_lag "Number of Densely Gender Equal IOs" numio_lag "Number of IOs" c.gendense_lag#c.libdem_lag "Densley Gender Equal IOs X Liberal Democracy" defense_lag "Defensive Alliance" libdem_lag "Democracy Score" inclusive_lag "Gender Inclusivity Score" cinc_lag "CINC Score" cumulative_in_lag "Cumulative MIDs" gdp_lag "GDP (logged)" time "Time" time2 "Time Squared" time3 "Time Cubed"  _cons "Constant" /lnsig2u "Sigma") ///
	title("A2: Interaction between liberal democracy score and membership in densely gender equal IOs, subsampled by gender equal states")

//Appendix3 using mid initiator, logged IO, subsampled by gender equal
xtset ccode1
xtlogit mid_initiate log_gendense numio_lag defense_lag libdem_lag inclusive_lag cinc_lag cumulative_in_lag gdp_lag time time2 time3 if inclusive_lag>.636
estimates store appendix_m3


*table A3
esttab appendix_m3 ///
using millerd-shared-ios-table1.rtf, replace b(%9.3f) ///
	se transform(ln*: exp(2*@) exp(2*@)) stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) ///
	star(* .05 ** .01 *** .001) ///
	mlabel("Logged IOs") ///
	eqlabels("" "Var(Group Level Errors)", none) ///
	varlabels(log_gendense "Number of Densely Gender Equal IOs" numio_lag "Number of IOs"  defense_lag "Defensive Alliance" libdem_lag "Democracy Score" inclusive_lag "Gender Inclusivity Score" cinc_lag "CINC Score" cumulative_in_lag "Cumulative MIDs" gdp_lag "GDP (logged)" time "Time" time2 "Time Squared" time3 "Time Cubed"  _cons "Constant" /lnsig2u "Sigma") ///
	title("A3: Logged membership in densely gender equal IOs, subsampled by gender equal states")

//Model Appendix4 using full IOs, using fatal_mid subset by gender-equal states
xtset ccode1
xtlogit fatal_mid gendense_lag numio_lag defense_lag libdem_lag inclusive_lag cinc_lag cumulative_in_lag gdp_lag time time2 time3 if inclusive_lag>.636
estimates store appendix_m4

*Table A4
esttab appendix_m4 ///
using millerd-shared-ios-table1.rtf, replace b(%9.3f) ///
	se transform(ln*: exp(2*@) exp(2*@)) stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) ///
	star(* .05 ** .01 *** .001) ///
	mlabel("Fatal MIDs") ///
	eqlabels("" "Var(Group Level Errors)", none) ///
	varlabels(log_gendense "Number of Densely Gender Equal IOs" numio_lag "Number of IOs"  defense_lag "Defensive Alliance" libdem_lag "Democracy Score" inclusive_lag "Gender Inclusivity Score" cinc_lag "CINC Score" cumulative_in_lag "Cumulative MIDs" gdp_lag "GDP (logged)" time "Time" time2 "Time Squared" time3 "Time Cubed"  _cons "Constant" /lnsig2u "Sigma") ///
	title("A4: Fatal MID as DV, subsampled by gender equal states")


//Appendix 5 - lagged with MID as DV and logged joint membership
use revthreshold50_io_gender_mid, clear

xtset dyad_id
xtlogit mid log_gendense numio_lag libdem1 libdem2 genderinclusive1 genderinclusive2 defense cont_lag kmdist_lag trade_lag cinc_lag cumulative_lag time time2 time3 if poli_relevant==1 & genderweak==1
estimates store appendix_m5 

*table for A5
esttab appendix_m5 ///
using millerd-shared-ios-table1.rtf, replace b(%9.3f) ///
	se transform(ln*: exp(2*@) exp(2*@)) stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) ///
	star(* .05 ** .01 *** .001) ///
	mlabel("Dyadic Fatal MIDs") ///
	eqlabels("" "Var(Group Level Errors)", none) ///
	varlabels(log_gendense "Logged Number of Shared Densely Gender Equal IOs" numio_lag "Number of IOs" defense_lag "Defensive Alliance" libdem1 "Democracy Score, Country 1" libdem2 "Democracy Score, Country 2" genderinclusive1 "Gender Exclusivity Score, Country 1" genderinclusive2 "Gender Exclusivity Score, Country 2" cinc_lag "CINC Score" cont_lag "Contiguity" kmdist_lag "Capital Distance"trade_lag "Trade Dependency" cumulative_lag "Cumulative MIDs" gdp_lag "GDP (logged)" time "Time" time2 "Time Squared" time3 "Time Cubed"  _cons "Constant" /lnsig2u "Sigma") ///
	title("A5: Logged Joint Membership in IOs, subsampled by politically relevant and gender-unequal dyads")


//Appendix 6 - lagged with fatal MID as DV and only using politically relevant; defensive alliance.
xtset dyad_id
xtlogit fatal_mid gendense_lag numio_lag libdem1 libdem2 genderinclusive1 genderinclusive2 defense cont_lag kmdist_lag trade_lag cinc_lag cumulative_lag time time2 time3 if poli_relevant==1 & genderweak==1
estimates store appendix_m6

*table for A6
esttab appendix_m6 ///
using millerd-shared-ios-table1.rtf, replace b(%9.3f) ///
	se transform(ln*: exp(2*@) exp(2*@)) stats(N ll, fmt(0 2) label("Observations" "Log-Likelihood")) ///
	star(* .05 ** .01 *** .001) ///
	mlabel("Dyadic Fatal MIDs") ///
	eqlabels("" "Var(Group Level Errors)", none) ///
	varlabels(gendense_lag "Number of Shared Densely Gender Equal IOs" numio_lag "Number of IOs" defense_lag "Defensive Alliance" libdem1 "Democracy Score, Country 1" libdem2 "Democracy Score, Country 2" genderinclusive1 "Gender Exclusivity Score, Country 1" genderinclusive2 "Gender Exclusivity Score, Country 2" cinc_lag "CINC Score" cont_lag "Contiguity" kmdist_lag "Capital Distance"trade_lag "Trade Dependency" cumulative_lag "Cumulative MIDs" gdp_lag "GDP (logged)" time "Time" time2 "Time Squared" time3 "Time Cubed"  _cons "Constant" /lnsig2u "Sigma") ///
	title("A6: Fatal MID as DV for dyadic MID participation, subsampled by politically relevant and gender-unequal dyads")
	
*Source Data:
//Barbieri, Katherine and Omar M. G. Omar Keshk. 2016. Correlates of War Project Trade Data Set Codebook, Version 4.0. Online: https://correlatesofwar.org.

//Coppedge, Michael, John Gerring, Carl Henrik Knutsen, Staffan I. Lindberg, Jan Teorell, David Altman, Michael Bernhard, Agnes Cornell, M. Steven Fish, Lisa Gastaldi, Haakon Gjerløw, Adam Glynn, Sandra Grahn, Allen Hicken, Katrin Kinzelbach, Kyle L. Marquardt, Kelly McMann, Valeriya Mechkova, Pamela Paxton, Daniel Pemstein, Johannes von Römer, Brigitte Seim, Rachel Sigman, Svend-Erik Skaaning, Jeffrey Staton, Eitan Tzelgov, Luca Uberti, Yi-ting Wang, Tore Wig, and Daniel Ziblatt. 2022. "V-Dem Codebook v12" Varieties of Democracy (V-Dem) Project

//Correlates of War Project. Direct Contiguity Data, 1816-2016. Version 3.2.

//"GDP per capita (constant 2015 US$)." 2022. World Bank.

//Leeds, Brett Ashley, Jeffrey M. Ritter, Sara McLaughlin Mitchell, and Andrew G. Long. 2002. Alliance Treaty Obligations and Provisions, 1815-1944. International Interactions 28: 237-260.

//Palmer, Glenn, Roseanne W. McManus, Vito D'Orazio, Michael R. Kenwick, Mikaela Karstens, Chase 	Bloch, Nick Dietrich, Kayla Kahn, Kellan Ritter, Michael J. Soules. 2020. "The MID5 Dataset, 2011-2014: Procedures, Coding Rules, and Description." Working paper.

//Pevehouse, Jon C.W., Timothy Nordstrom, Roseanne W McManus, Anne Spencer Jamison. "Tracking 	Organizations in the World: The Correlates of War IGO Version 3.0 datasets". Journal of Peace  	Research.

//Singer, J. David. 1987. "Reconstructing the Correlates of War Dataset on Material Capabilities of States, 1816-1985" International Interactions, 14: 115-32

//Stinnett, Douglas M., Jaroslav Tir, Philip Schafer, Paul F. Diehl, and Charles Gochman. 2002. "The Correlates of War Project Direct Contiguity Data, Version 3." Conflict Management and Peace Science 19(2):58-66.

